package com.cqemme.activitiservice.utils;

import java.util.Collection;
import java.util.Map;

public class EmptyChecker {
    private EmptyChecker() {

    }

    public static boolean isEmpty(Object obj) {
        if (obj != null && !"null".equals(obj.toString()) && !"".equals(obj.toString())) {
            if (obj instanceof String) {
                return ((String) obj).trim().length() == 0;
            } else if (obj instanceof Collection) {
                return ((Collection) obj).isEmpty();
            } else {
                return obj instanceof Map ? ((Map) obj).isEmpty() : false;
            }
        } else {
            return true;
        }
    }


    public static boolean notEmpty(Object obj) {
        return !isEmpty(obj);
    }

    public static boolean isEmpty(Object[] array) {
        return array == null || array.length == 0;
    }

    public static boolean isAnyOneEmpty(Object... obj) {
        for (int i = 0; i < obj.length; i++) {
            boolean empty = isEmpty(obj[i]);
            if (empty) {
                return true;
            }

        }
        return false;
    }

    public static boolean isAllEmpty(Object... obj) {
        for (int i = 0; i < obj.length; i++) {
            boolean temp = notEmpty(obj[i]);

            if (temp) {
                return true;
            }

        }

        return false;
    }
}
